package com.mxx.common.security.displacer;

import com.mxx.common.utils.SignUtil;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @Author itzgyw
 * @Date 2020-02-24
 * @Time 0:24
 * @Description:
 */
public class HexDisplacer implements Displacer {


    private final Charset charset;

    public HexDisplacer() {
        this.charset = StandardCharsets.UTF_8;
    }

    public HexDisplacer(Charset charset) {
        this.charset = charset;
    }

    @Override
    public byte[] encoder(byte[] bytes) {
        return SignUtil.byteToHex(bytes).getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public byte[] decoder(byte[] bytes) {
        return SignUtil.hexToByte(toString(bytes));
    }

    @Override
    public Charset getCharset() {
        return this.charset;
    }
}
